<%@ page import="net.zjitc.eljstl.User" %>
<%@ page import="java.util.*" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/6/11
  Time: 13:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>EL表达式</title>
</head>
<body>
<%--EL作用：用来简化和替换jsp页面中的Java代码--%>
    <h2>EL运算</h2>
    ${1+2}
    ${3>2}
<h2>判断是否为空emply</h2>
${empty str}
${not empty str}
<%/*往request域喝session域保存一些信息
 * 然后再用EL表达式获取域对象中的内容*/
    request.setAttribute("msg","haha");

    request.getSession().setAttribute("msg","aaa");
%>
<h2>从域对象获取值</h2>
<%--若不指定哪个域，默认先从request域中找，没有的话再找session域--%>

${msg}
<%--表示从session域获取内容--%>
${sessionScope.msg}
<h2>获取对象的值</h2>
<%
    /*准备数据：对象，List ，Map*/
    User user=new User("张三",18,new Date());
    request.setAttribute("u",user);

    List<String> list=new ArrayList<String>();
    list.add("lily");
    list.add("tom");
    request.setAttribute("list",list);

    Map<String,User> map=new HashMap<String, User>();
    map.put("zs",user);
    request.setAttribute("map",map);
%>
<%--获取域对象的值，是从域对象获取
    域对象.key.属性名
    域对象可以省略，默认会先从request域中找再session
   --%>
${u} <br>
${u.name}<br>
${u.birthday}<br>
${u.birthday.month}<br>
<%--实质上是调用getter方法--%>
${u.birStr}

<h2>获取List的值</h2>
${list}<br>
${list[0]}

<h2>获取Map的值</h2>
${map}<br>
${map.zs.name}
<h2>动态获取项目路径</h2>
<%=request.getContextPath()%>
${pageContext.request.contextPath}
</body>
</html>
